package com.yang;


public class Work2 {
    public static void main(String[] args) {
        Node n1 = new Node(1, "aa");
        Node n2 = new Node(2, "bb");
        Node n3 = new Node(3, "cc");
        Node n4 = new Node(4, "dd");
        Node n5 = new Node(5, "ee");
        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        n4.next = n5;
        n5.next = n1;
        System.out.println(operator(n1));
    }

    public static boolean operator(Node head) {
        if (head == null) return false;
        //定义快慢指针
        Node slow = head; //慢指针
        Node fast = head.next; //快指针
        while (fast != null && fast.next != null) {
            //有环
            if (slow == fast) {
                return true;
            }
            //定义步长
            fast = fast.next.next;// 快指针步长为2
            slow = slow.next;//慢指针步长为1
        }
        return false;
    }
}
